<html>
    <body style="background: url(images/background.jpg);">
        <?php
            require 'config/dataSource.php';
            session_start();  
            //The following does a check to see if the user is logged in, or sent back to the log in page
            //need to double check things with ivan before implementing
            //if(!isset($_SESSION['uid'])|| $_GET('cid')){
              //  header("Location: index.php");
              //  exit();
              //  }
            //$cid = $_GET['cid'];
            
        ?>
        <div>
            <h1><a href="forumIndex.php?<?php echo htmlspecialchars(SID); ?>">Return to Forum Index</a></h1>
            <h1><a href="topicIndex.php?<?php echo htmlspecialchars(SID); ?>">Return to Topic Index</a></h1>
        </div>
        
        <div>
            <form action="createTopic.php" method="post">
                <p>Topic Title</p>
                <input type="text" name="topicTitle" size="98" maxlength="255"/>
                <p>Reply Content</p>
                <textarea name="contentOfReply" rows="5" colums="75"></textarea>
                <br><br>
                <!--<input type="hidden" name="cid" value="<?php echo $cid;?>"/>-->
                <input type="submit" name="topic_submit" value="Post your Topic"/>
                <?php
                if(isset($_POST['topic_submit'])){
                    if(($_POST['topicTitle'] == "")){
                        echo "You must enter a title for your topic.";
                    }
                    else if(($_POST['contentOfReply']=="")){
                        echo "Your reply must have content";
                    }
                    else{
                        $title = $_POST['topicTitle'];
                        $content = $_POST['contentOfReply'];
                        $owner = $_SESSION['uid'];//id?sid?
                        //$temp = 2;//I just needed something to put as the tid. not sure how to autogenerate that
                        $sql = "INSERT INTO topic (topicTitle, owner, lastUpdatedBy, dateCreated, dateUpdated, numberOfReplies) "
                                . "VALUES ('".$title."','".$owner."','".$owner."' now(), now(), 0)";
                        //TO DO: Figure out how to pass and gather the forum & Topic ids so i can actually use them
                        $sqlReply = "INSERT INTO reply (contentOfReply, dateCreated, dateUpdated, owner) VALUES('".$content."', now(), now(),'".$owner."')";
                    }
                }
                ?>
                <!--the above i based on a tutorial, but it seems wrong. Will compare with Chad's forum creation
                tomorrow.--->
            </form>
            
        </div>
        <?php
            
        ?> 
       <div>
            <h1><a href="forumIndex.php?<?php echo htmlspecialchars(SID); ?>">Return to Forum Index</a></h1>
            <h1><a href="topicIndex.php?<?php echo htmlspecialchars(SID); ?>">Return to Topic Index</a></h1>
       </div> 
    </body>
</html>